<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/23
 * Time: 9:23
 */

namespace Admin\Model;


class CategoryModel extends \Think\Model{

    protected  $_auto =array(
        array('create_time','time',1,'function'),

    );


    function all_category($type){

        $category =$this->where('category_type=%d',array($type))->order('sort desc')->select();


        foreach ($category as $key =>$val){

            $category_name=$this->field('category_name')->where('category_type=%d AND id=%d',array($type,$val['upper_level']))->find();

            if($category_name){
                $category[$key]['upper_level'] =$category_name['category_name'];
            }else{
                $category[$key]['upper_level']='无';
            }
        }
       return $category;
    }

    function edit($type,$id){

        $sql =$this->where('category_type=%d AND id=%d',array($type,$id))->find();


        return $sql;
    }



}